package com.ljz.servlet;

import com.google.gson.Gson;
import com.ljz.dao.DeptmeDao;
import com.ljz.entity.Deptme;
import com.ljz.utils.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/getdeptmes")
public class DeptmeInforServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        SqlSession sqlSession = SqlSessionFactoryUtil.getSqlSession();
        DeptmeDao deptmeDao = sqlSession.getMapper(DeptmeDao.class);
        List<Deptme> list = deptmeDao.findAll();
        Gson gson = new Gson();
        String json = gson.toJson(list);
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(json);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
